package org.jerry.virtualoperator.config;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * @Date 2020/11/23
 * @Created JerryZeng
 */

@Configuration
public class ThreadPoolConfig {


    @Bean(destroyMethod = "shutdown")
    public ThreadPoolTaskExecutor fileReadExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);
        executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 2 + 2);
        executor.setKeepAliveSeconds(10);
        executor.setQueueCapacity(1024);
        executor.setThreadNamePrefix("mobile-file-read");
        return executor;
    }

    @Bean(destroyMethod = "shutdown")
    public ThreadPoolTaskExecutor mobileReportExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 3);
        executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 3 + 2);
        executor.setKeepAliveSeconds(60);
        executor.setQueueCapacity(2048);
        executor.setThreadNamePrefix("report");
        return executor;
    }

    @Bean(destroyMethod = "shutdown")
    public ScheduledExecutorService springScheduler() {
        return Executors.newScheduledThreadPool(10);
    }
}
